#include "File.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
SK

File::File (const File& other)
: size (-1), handle (NULL)
{
}

File::File ()
: size (-1), handle (NULL)
{
}

File::~File ()
{
	close();
}

bool File::open (const String& path, const String& mode)
{
    this->path = path;
    fopen_s (&handle, path.c_str(), mode.c_str());
	return handle!= NULL;
}

void File::close (void)
{
	if (handle)
		fclose (handle);

    handle = NULL;
	size = -1;
}

int File::read (byte *buffer, u32 size)
{
	return fread (buffer, 1, size, handle);
}

int File::getSize (void)
{
	if (size < 0)
	{
		struct stat ret;
        stat (path.c_str(), &ret);
        size = ret.st_size;
	}

	return size;
}

EK